home *** CD-ROM | disk | FTP | other *** search
- /* DgvCon.c
- * 1990/09/20
- * Version 0.02 -- Public Domain
- */
-
- /* by Jim Omura, 2A King George's Drive,
- * Toronto, Ontario, M6M 2G9
- * BIX 'jimomura'
- */
-
- /* dgvcon [-v?] [-b=nnn] [-c=nnn] [-p=n] [-t=n] [infile] [outfile]
- * Dash Flags:
- *
- * ? Short Help
- * b Bright +/-255
- * c Contrast %
- * p bit Planes (7 or 8 -- default is 8)
- * t type (1 = 320*200, 2 = 640*400, default = 2)
- * v Verbose.
- */
-
- /* The '-t' switch is not implimented at this time.
- * The main support code for this switch has been
- * included, but I don't have a test file.
- */
-
- /* The actual IFF/ILBM header should be of the type:
-
- typedef struct * BitMapHeader *
- {
- USHORT bm_w,
- bm_h,
- bm_x,
- bm_y;
- UBYTE bm_nplanes, * UBYTE *
- bm_masking,
- bm_comp, * Compression *
- bm_pad1;
- USHORT bm_trans; * Transparent color *
- UBYTE bm_xaspect, * UBYTE *
- bm_yaspect;
- short bm_pgwidth, * USHORT? *
- bm_pgheight;
- } IFFBMHDR;
-
- * but the the 68000 processor has problems with Bytewide
- * data. As such, the Sozobon C creates 16 bit aligned variables
- * which are misaligned if you try to read or write the
- * actual header into the memory structure as declared.
- * In order to avoid this, 'bm_dmwd1' (dummy word 1) style
- * data has been used and separate variables "manually" packed
- * and unpacked where necessary.
- *
- * This module has been ported to the Atari ST via Sozobon C
- * version 1.2. My version of the compiler has been patched
- * by Ian Lepore of BIX. The only "unofficial" patch is to the
- * TOP optimizer. Since the patch is not official yet, it is
- * not likely you will have it unless you have a later version of
- * Sozobon C. The best advice is to NOT use the TOP optimizer
- * if you are using Sozobon C 1.2 or earlier.
- */
-
- #include <stdio.h>
- #include <fcntl.h>
-
- #include "dgvcon.h"
-
- /* ------------------------------------------------------- */
-
- /* Global Variables */
-
-
- int bright; /* Brightness */
- int contrast;
- int inlen;
- int planes; /* IFF Bit Planes */
- int verbose;
- int white; /* White value for bright adjust */
-
- unsigned char cbyte[1]; /* Conversion Byte */
- /* USHORT conbuf[8]; /* Conversion Buffer */
- unsigned char inbuf[DGVBYTES]; /* Input File buffer */
- USHORT outbuf[IFFWMAX]; /* Output File buffer */
-
- IFFBMHDR hdrstr; /* IFFbitmapheader struct */
-
- /* ------------------------------------------------------- */
-
- main(argc,argv)
-
- int argc;
- char **argv;
-
- {
- static char ifhbmhd[4] =
- {
- 'B','M','H','D'
- };
- static char ifhbody[4] =
- {
- 'B','O','D','Y'
- };
- static char ifhcmap[4] =
- {
- 'C','M','A','P'
- };
- static char ifhform[4] =
- {
- 'F','O','R','M'
- };
- static char ifhilbm[4] =
- {
- 'I','L','B','M'
- };
-
- #ifdef ATARI_ST
- static IFFBMHDR hdrdef = /* IFFbitmapheader struct */
- {
- 640, 400, /* Width, Height */
- 0, 0, /* X, Y offsets */
- 0x0800, /* 8 Bit Planes, no mask */
- 0x0000, /* Compression == 0, pad byte == 0 */
- 0, /* Transparent colour */
- 0x0101, /* xAspect, yAspect */
- 640, 400
- };
- #else
- static IFFBMHDR hdrstr = /* IFFbitmapheader struct */
- {
- 640, 400, /* Width, Height */
- 0, 0, /* X, Y offsets */
- 8, /* Bit Planes */
- 0, /* No Mask == 0 */
- 0, /* Compression == 0 */
- 0, /* Pad byte */
- 0, /* Transparent colour */
- 1, 1, /* xAspect, yAspect */
- 640, 400
- };
- #endif
-
- /* End of Static Variables. */
-
- int cntr; /* Local counter */
- #ifdef ATARI_ST
- int errno; /* OS-9 standard variable for errors */
- #endif
- int fdone; /* Field done */
- /* long ifflen; /* IFF Chunk length */
- long iflnbmhd; /* Chunk Lengths */
- long iflnbody;
- long iflncmap;
- long iflnform;
- long iflnilbm;
-
- int inpath; /* Input File pointer */
- int lastln; /* Last line */
- int lncntr; /* Line Counter */
- int nclrs; /* Number of Colour Registers */
- int newfflag; /* New Field Flag */
-
- int outlen; /* Bytes written for output */
- int outpath; /* Output File pointer */
- register int offset; /* Input buffer offset */
- char *strpntr; /* String Pointer for Write() */
-
- int report; /* Function return codes */
-
- /* Set Defaults */
-
- bright = 0;
- contrast = 100;
- inpath = STDIN;
- outpath = STDOUT;
- planes = 8;
- verbose = FALSE;
-
- hdrstr.bm_w = hdrdef.bm_w;
- hdrstr.bm_h = hdrdef.bm_h;
- hdrstr.bm_x = hdrdef.bm_x;
- hdrstr.bm_y = hdrdef.bm_y;
- hdrstr.bm_dmwd1 = hdrdef.bm_dmwd1;
- hdrstr.bm_dmwd2 = hdrdef.bm_dmwd2;
- hdrstr.bm_trans = hdrdef.bm_trans;
- hdrstr.bm_dmwd3 = hdrdef.bm_dmwd3;
- hdrstr.bm_pgwidth = hdrdef.bm_pgwidth;
- hdrstr.bm_pgheight = hdrdef.bm_pgheight;
-
- for ( --argc ; (argc > 0) ; --argc )
- {
- ++argv;
-
- if(**argv == '-')
- {
- dashflag(*argv);
- }
- else
- {
-
- if (inpath == STDIN)
- {
- inpath = open(*argv,O_RDONLY);
- if (inpath < -3)
- {
- exit(inpath);
- }
- } /* End branch Open inpath */
- else
- {
- outpath = creat(*argv,0);
- errno = outpath;
- if (outpath == ERROR)
- {
- exit(errno);
- } /* Endif output file error */
- } /* Endif Infile/Outfile openning */
- } /* Endif Dash/Not dash parameters */
- } /* Endloop Get Arguments */
-
- /* **If multiple files implimented then loop will start here.** */
-
- newfflag = TRUE;
-
- inlen = DGVBYTES; /* This may be changed later if Dash switch. */
- outlen = (hdrstr.bm_w * planes / 8); /* Up to 640 bytes */
- lastln = (hdrstr.bm_h - 1); /* Usually 400 lines */
-
- cntr = planes;
- white = 0;
- for(;;)
- {
- white = white << 1;
- ++white;
- --cntr;
- if(cntr == 0)
- {
- break;
- }
- } /* Endloop No. Colours */
- nclrs = white + 1;
-
- /* Write IFF Header: */
-
- iflnbmhd = 20; /* sizeof(hdrstr) */
- iflncmap = (nclrs * 3); /* 3 bytes per colour */
- iflnbody = (long) (hdrstr.bm_h * outlen); /* (lns * bytes) */
-
- /* (3 headers) * (8 bytes ea.) = 24 */
- iflnilbm = (unsigned) (24 + iflnbmhd + iflncmap + iflnbody);
-
- iflnform = (unsigned) iflnilbm + 4;
-
- write(outpath,ifhform,4);
- write(outpath,&iflnform,4);
-
- write(outpath,ifhilbm,4);
- /* write(outpath,&iflnilbm,4); IRREGULAR Chunk header -- No Length! */
-
- write(outpath,ifhbmhd,4);
- write(outpath,&iflnbmhd,4);
-
- strpntr = (char *)(&hdrstr.bm_w); /* This style should work for all C */
- write(outpath,strpntr,20); /* Write Structure */
-
- write(outpath,ifhcmap,4);
- write(outpath,&iflncmap,4);
-
- lncntr = 0; /* No particular reason to use 'lncntr' */
- cbyte[0] = 0;
- for(;;)
- {
- if(lncntr == nclrs)
- {
- break;
- }
- cntr = 0;
- for(;;)
- {
- if(cntr == 3)
- {
- break;
- }
- write(outpath,cbyte,1);
- ++cntr;
- } /* Endloop write 3 times */
-
- ++lncntr;
- cbyte[0] = lncntr * 255 / (nclrs - 1);
-
- } /* Endloop write IFF Color Map */
-
- write(outpath,ifhbody,4);
- write(outpath,&iflnbody,4);
-
- /* Convert Digiview File and Store */
- lncntr = 0;
- fdone = FALSE;
- for(; (fdone == FALSE) ;)
- {
-
- /* Get an Input Line */
- offset = 0;
- report=read(inpath,inbuf,inlen);
-
- if (report != inlen)
- {
- fprintf(stderr,"DGVCON: File short\n");
- }
-
- /* Convert The Line */
-
- toiff();
-
- write(outpath,outbuf,outlen); /* Store the line. */
- ++lncntr;
-
- if (lncntr > lastln)
- {
- fdone = TRUE;
- }
- }
- exit(0);
-
- } /* End of main() */
-
- /* -------------------------------------------------------- */
-
- dashflag(param)
-
- char *param;
-
- {
- extern int bright;
- extern int contrast;
- extern int planes;
- extern int verbose;
-
- for (; (*param != '\0') ; ++param)
- {
- switch ((int)*param)
- {
- case '?':
- shorthelp();
- exit(0);
- case 'b':
- ++param;
- if (*param == '=')
- {
- ++param;
- }
- bright = atoi(param);
- continue;
- case 'c':
- ++param;
- if (*param == '=')
- {
- ++param;
- }
- contrast = atoi(param);
- continue;
- case 'p':
- ++param;
- if (*param == '=')
- {
- ++param;
- }
- planes = atoi(param);
- continue;
- case 't':
- ++param;
- if (*param == '=')
- {
- ++param;
- }
- if(atoi(param) == 1)
- {
- hdrstr.bm_w = 320;
- hdrstr.bm_h = 200;
- }
- continue;
- case 'v':
- verbose = TRUE;
- continue;
- default:
- continue;
- } /* Endswitch */
- } /* Endloop */
- } /* End of dashflag() */
-
- /* -------------------------------------------- */
-
- shorthelp()
- {
- printf("DgvCon Converts Digiview IP uncompressed file to ");
- printf("IFF/ILBM formats.\n\n");
- printf("dgvcon [-?v] [-b=nn] [-c=nn] [-p=n] [-t=n] ");
- printf("[infile] [outfile]\n\n");
- printf("Dash Flags:\n");
- printf(" ? Short Help\n");
- printf(" b Bright +/-255\n");
- printf(" c Contrast %%\n");
- printf(" p IFF Bit Planes (1-8)\n");
- printf(" t type (1 = 320*200, 2 = 640*400, default = 2)\n");
- printf(" v Verbose.\n");
-
- } /* End of shorthelp() */
-
- /* End of DgvCon.c */
-